const storage = {}

/**
 * @description 存储 localstorage 值
 * @param {String} name localstorage name
 * @param {String} value localstorage value
 */
storage.set = function (name, value) {
  localStorage.setItem(`zerovue-${process.env.VUE_APP_VERSION}-${name}`, value)
}

/**
 * @description 拿到 localstorage 值
 * @param {String} name localstorage name
 */
storage.get = function (name) {
  return localStorage.getItem(`zerovue-${process.env.VUE_APP_VERSION}-${name}`)
}

/**
 * @description 删除 localstorage
 * @param {String} name localstorage name
 */
storage.remove = function (name) {
  return localStorage.removeItem(`zerovue-${process.env.VUE_APP_VERSION}-${name}`)
}

/**
 * @description 删除项目相关所有 localstorage
 * @param {String} name localstorage name
 */
storage.removeAll = function () {
  Object.keys(localStorage).forEach(item => item.indexOf(`zerovue-${process.env.VUE_APP_VERSION}`) !== -1 ? localStorage.removeItem(item) : '')
}

export default storage
